<?php

$usrnm = $_GET['usrnm'];
$pswd = $_GET['pswd'];
$firstName = $_GET['fname'];
$lastName = $_GET['lname'];
$sex = $_GET['s'];
$bday = $_GET['dob'];

//$con = mysql_connect("localhost" , "user1789586" , "adobephotoshopcs5");
$con = mysql_connect("localhost" , "root" );
mysql_select_db("db1789586-main",$con);

//create table if not exist
//dob = DD-MM-YYYY
$query = 'CREATE TABLE IF NOT EXISTS usrdetails 
	(
	usrnm varchar(150) PRIMARY KEY,
	pswd varchar(32),
	fname varchar(50),
	lname varchar(50),
	sex varchar(1),
	dob varchar(10)
	)';
	
$result = mysql_query($query);
	
$query = "INSERT INTO usrdetails (usrnm, pswd, fname, lname, sex, dob) VALUE ('".$usrnm."', '".$pswd."', '".$firstName."', '".$lastName."', '".$sex."', '".$bday."')";

$result = mysql_query($query);

if(!$result){
	$arr = array('result'=>mysql_error());
	echo json_encode($arr);
	die("");
}
else{
	makeDir("profiles/".$usrnm);
	$arr = array('result'=>'success');
	echo json_encode($arr);
}

function makeDir($path)
{
   return is_dir($path) || mkdir($path);
}


?>